package com.ruoyi.product.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.product.domain.AICode;
import com.ruoyi.product.domain.Product;
import com.ruoyi.product.service.AICodeService;
import com.ruoyi.system.service.ISysDictDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * AI码管理
 */
@RestController
@RequestMapping("/business/aiCode")
public class    AICodeController extends BaseController {

    @Autowired
    private AICodeService aiCodeService;

    @Autowired
    private ISysDictDataService dictDataService;

    private String prefix = "product";

    /**
     * 查询采购订单入库信息
     */

    @GetMapping("/selectEdit/{productId}")
    public Map<String,Object> operlog(@PathVariable("productId") Long productId) {

        Long companyId =SecurityUtils.getLoginUser().getUser().getCompanyId();
        Map<String,Object> resMap=new HashMap<>();
        resMap.put("productId",productId);
        resMap.put("deptId",companyId);
        AICode aiCode = new AICode();
        aiCode.setDeptId(companyId);
        aiCode.setProductId(productId);
        List<AICode> aiCodes = aiCodeService.selectAICode(aiCode);
        resMap.put("aiCodes",aiCodes);

        return resMap;
    }

    /**
     * 查询产品AI码信息列表
     */

    @PostMapping("/list/{productId}")
    @ResponseBody
    public TableDataInfo list(@PathVariable("productId") Long productId, AICode aiCode) {
        ArrayList<Object> list = new ArrayList<>();
        return getDataTable(list);
    }

    /**
     * 保存产品AI码
     */
    @Log(title = "保存产品AI码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody  Product product) {
         product.setDeptId(SecurityUtils.getLoginUser().getUser().getDeptId());
        return toAjax(aiCodeService.insertAICodeList(product.getAiCodes(),product.getDeptId(),product.getProductId()));
    }

}
